package game_objects;
import game_states.Game;
import processing.core.*;

public class Player extends Rectangle{

	//Instance Variables
	private PImage image;
	private Game g;
	private static float PLAYER_WIDTH=33;
	private static float PLAYER_HEIGHT=54;
	private boolean jump = false;
	private boolean fall = false;
	private boolean done = false;
	private float jumpcount = 250;
	private int count = 0;
	private float counter = jumpcount;
	private float state;
	private float playerX1, playerY1, playerWidth, playerHeight, playerX2, playerY2;

	

	public Player(PApplet parent, float x, float y, float width, float height, PImage i) 
	{
		super(parent, x, y, width, height);
		image = i;
		playerX1 = this.getX();
		playerY1 = this.getY();
		playerWidth = this.getWidth();
		playerHeight = this.getHeight();
		playerX2 = playerX1+playerWidth;
		playerY2 = playerY1+playerHeight;
	}

	public PImage getImage() 
	{
		return image;
	}

	public void setImage(PImage image) 
	{
		this.image = image;
	}

	public static float getPLAYER_WIDTH() 
	{
		return PLAYER_WIDTH;
	}

	public static void setPLAYER_WIDTH(float pLAYER_WIDTH) 
	{
		PLAYER_WIDTH = pLAYER_WIDTH;
	}

	public static float getPLAYER_HEIGHT() 
	{
		return PLAYER_HEIGHT;
	}

	public static void setPLAYER_HEIGHT(float pLAYER_HEIGHT) 
	{
		PLAYER_HEIGHT = pLAYER_HEIGHT;
	}

	public float getPlayerX1() {
		return playerX1;
	}

	public void setPlayerX1(float playerX1) {
		this.playerX1 = playerX1;
	}

	public float getPlayerY1() {
		return playerY1;
	}

	public void setPlayerY1(float playerY1) {
		this.playerY1 = playerY1;
	}

	public float getPlayerWidth() {
		return playerWidth;
	}

	public void setPlayerWidth(float playerWidth) {
		this.playerWidth = playerWidth;
	}

	public float getPlayerHeight() {
		return playerHeight;
	}

	public void setPlayerHeight(float playerHeight) {
		this.playerHeight = playerHeight;
	}

	public float getPlayerX2() {
		return playerX2;
	}

	public void setPlayerX2(float playerX2) {
		this.playerX2 = playerX2;
	}

	public float getPlayerY2() {
		return playerY2;
	}

	public void setPlayerY2(float playerY2) {
		this.playerY2 = playerY2;
	}

	@Override
	public void draw(boolean drawRect) 
	{	
		super.draw(false);
		if (jump && drawRect)
		{
			if (jumpcount != 0 && !fall)
			{
				jumpcount-=6;
				count+=6;
				playerY1-=6;
				playerY2-=6;
				parent.image(image, getX(), getY()-count);
				//System.out.println("PlayerY = "+getY());
				//System.out.println(state);
				
				state = getY() - count;
				if (jumpcount <= 0)
				{
					fall = true;	
				}
			}
			if (jumpcount != count && fall)
			{
			
				jumpcount+=3;
				playerY1+=3;
				playerY2+=3;
				parent.image(image, getX(), state +jumpcount);
				//Note, if space is held then the jump is slower, incude this with instructions
				
				//System.out.println(state+jumpcount);
				if (jumpcount >= 250  && fall)
				{
					fall = false;
					done = true;
					jump(done);
					return;
				}
				//System.out.println(count);
			}

		}
		else if (drawRect & !jump)
		{
			parent.image(image, getX(), getY());
		}
		return;
	}

	public boolean jump(boolean Jumpdone)
	{

		//Jumpdone = done;
		//System.out.println(Jumpdone);
		if (!Jumpdone)
		{
			return jump = true;
		}
		else 
		{
			count = 0;
			return	jump = false;
		}
	}
}